﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.LawArchives.LawCaseSafetyView
{
    public partial class LawCaseSafetyViewUserControl : UserControl
    {
        public int _caseId
        {
            set { ViewState["_caseId"] = value; }
            get { return (int)ViewState["_caseId"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (LawCaseProxy proxy = new LawCaseProxy())
                {
                    if (Request.QueryString["CaseId"] != null)
                    {
                        _caseId = Int32.Parse(Request.QueryString["CaseId"].ToString());
                    }
                    // load data
                    var loadDT = proxy.GetLawCaseSafety(_caseId, string.Empty);
                    LoadForEdit(loadDT);
                    LoadForView(loadDT);
                }

            }


            // switch controls
            if (this.hfIsEdit.Value != "1")
                SwitchControls(true, false);
            else
                SwitchControls(false, true);
        }

        private void SwitchControls(bool isLabelsShow, bool isControlsShow)
        {
            // hide the lables
            this.lblCaseName.Visible = isLabelsShow;
            this.lblCaseOperator.Visible = isLabelsShow;
            this.lblCaseInitial.Visible = isLabelsShow;
            this.lblCaseFiller.Visible = isLabelsShow;
            this.lblFillDate.Visible = isLabelsShow;
            this.lblCase1.Visible = isLabelsShow;
            this.lblCase2.Visible = isLabelsShow;
            this.lblCase3.Visible = isLabelsShow;
            this.lblCase4.Visible = isLabelsShow;
            this.lblCase5.Visible = isLabelsShow;
            this.lblCase6.Visible = isLabelsShow;
            this.lblCase7.Visible = isLabelsShow;
            this.lblCase8.Visible = isLabelsShow;
            this.lblCase9.Visible = isLabelsShow;
            this.lblCase10.Visible = isLabelsShow;

            this.lblRemark1.Visible = isLabelsShow;
            this.lblRemark2.Visible = isLabelsShow;
            this.lblRemark3.Visible = isLabelsShow;
            this.lblRemark4.Visible = isLabelsShow;
            this.lblRemark5.Visible = isLabelsShow;
            this.lblRemark6.Visible = isLabelsShow;
            this.lblRemark7.Visible = isLabelsShow;
            this.lblRemark8.Visible = isLabelsShow;
            this.lblRemark9.Visible = isLabelsShow;
            this.lblRemark10.Visible = isLabelsShow;

            // show controls
            this.txtCaseName.Visible = isControlsShow;
            this.txtCaseOperator.Visible = isControlsShow;
            this.txtCaseInitial.Visible = isControlsShow;
            this.txtCaseFiller.Visible = isControlsShow;
            this.dtFillDate.Visible = isControlsShow;
            this.rbCase1.Visible = isControlsShow;
            this.rbCase2.Visible = isControlsShow;
            this.rbCase3.Visible = isControlsShow;
            this.rbCase4.Visible = isControlsShow;
            this.rbCase5.Visible = isControlsShow;
            this.rbCase6.Visible = isControlsShow;
            this.rbCase7.Visible = isControlsShow;
            this.rbCase8.Visible = isControlsShow;
            this.rbCase9.Visible = isControlsShow;
            this.rbCase10.Visible = isControlsShow;

            this.txtRemark1.Visible = isControlsShow;
            this.txtRemark2.Visible = isControlsShow;
            this.txtRemark3.Visible = isControlsShow;
            this.txtRemark4.Visible = isControlsShow;
            this.txtRemark5.Visible = isControlsShow;
            this.txtRemark6.Visible = isControlsShow;
            this.txtRemark7.Visible = isControlsShow;
            this.txtRemark8.Visible = isControlsShow;
            this.txtRemark9.Visible = isControlsShow;
            this.txtRemark10.Visible = isControlsShow;

            this.hr6.Visible = isControlsShow;
        }

        private void LoadForView(LawCaseDataSet.T_SelfOperateDataTable loadDT)
        {
            var loadRow = loadDT[0];
            this.lblCaseName.Text = loadRow.CaseName;
            this.lblCaseOperator.Text = loadRow.CaseOperator;
            this.lblCaseInitial.Text = loadRow.CaseInitial;
            this.lblCaseFiller.Text = loadRow.CaseFiller;
            this.lblFillDate.Text = loadRow.FillDate.ToString(JCYConstant.Date_Format_CN);

            this.lblCase1.Text = loadRow.Case_1;
            this.lblCase2.Text = loadRow.Case_2;
            this.lblCase3.Text = loadRow.Case_3;
            this.lblCase4.Text = loadRow.Case_4;
            this.lblCase5.Text = loadRow.Case_5;
            this.lblCase6.Text = loadRow.Case_6;
            this.lblCase7.Text = loadRow.Case_7;
            this.lblCase8.Text = loadRow.Case_8;
            this.lblCase9.Text = loadRow.Case_9;
            this.lblCase10.Text = loadRow.Case_10;

            this.lblRemark1.Text = loadRow.Remark_1;
            this.lblRemark2.Text = loadRow.Remark_2;
            this.lblRemark3.Text = loadRow.Remark_3;
            this.lblRemark4.Text = loadRow.Remark_4;
            this.lblRemark5.Text = loadRow.Remark_5;
            this.lblRemark6.Text = loadRow.Remark_6;
            this.lblRemark7.Text = loadRow.Remark_7;
            this.lblRemark8.Text = loadRow.Remark_8;
            this.lblRemark9.Text = loadRow.Remark_9;
            this.lblRemark10.Text = loadRow.Remark_10;
        }

        private void LoadForEdit(LawCaseDataSet.T_SelfOperateDataTable loadDT)
        {
            var loadRow = loadDT[0];
            this.txtCaseName.Text = loadRow.CaseName;
            this.txtCaseOperator.Text = loadRow.CaseOperator;
            this.txtCaseInitial.Text = loadRow.CaseInitial;
            this.txtCaseFiller.Text = loadRow.CaseFiller;
            this.dtFillDate.SelectedDate = loadRow.FillDate;
            this.hfEditDate.Value = loadRow.FillDate.ToString();

            this.rbCase1.Text = loadRow.Case_1;
            this.rbCase2.Text = loadRow.Case_2;
            this.rbCase3.Text = loadRow.Case_3;
            this.rbCase4.Text = loadRow.Case_4;
            this.rbCase5.Text = loadRow.Case_5;
            this.rbCase6.Text = loadRow.Case_6;
            this.rbCase7.Text = loadRow.Case_7;
            this.rbCase8.Text = loadRow.Case_8;
            this.rbCase9.Text = loadRow.Case_9;
            this.rbCase10.Text = loadRow.Case_10;

            this.txtRemark1.Text = loadRow.Remark_1;
            this.txtRemark2.Text = loadRow.Remark_2;
            this.txtRemark3.Text = loadRow.Remark_3;
            this.txtRemark4.Text = loadRow.Remark_4;
            this.txtRemark5.Text = loadRow.Remark_5;
            this.txtRemark6.Text = loadRow.Remark_6;
            this.txtRemark7.Text = loadRow.Remark_7;
            this.txtRemark8.Text = loadRow.Remark_8;
            this.txtRemark9.Text = loadRow.Remark_9;
            this.txtRemark10.Text = loadRow.Remark_10;
        }
    }
}
